<template>
  <div class="comment" >
    <div class="comment_userinfo">
      <div class="userinfo_left">
        <img :src="avatar" alt="" />
        <p>{{nickname}}</p>
      </div>
      <div class="userinfo_right">
        <van-icon name="good-job" :color="isLike ? '#900' : '#666' " @click="commentLike" /><span class="sum">{{likecount}}</span>
      </div>
    </div>
    <p class="content" @click="Reply">
      {{content}}
    </p>
    <div class="footer">
      <div class="footer_left">
        <p @click="Reply">{{replynum}}回复<van-icon name="arrow" /></p>
        <span>{{formatime}}</span>
      </div>
      <div class="footer_right">
        <van-icon name="ellipsis" />
      </div>
    </div>
  </div>
</template>

<script>
import formatTime from '@/utils/time'
import { mapState } from 'vuex'
import { commentlike,recommentlike } from '@/api/api'
export default {
  components:{
    
  },
  props:{
    avatar:String,
    content: String,
    nickname:String,
    is_like:Boolean,
    like_count:Number,
    time:Number,
    _id:String,
    reply_num:Number,
    index:Number

  },
    data(){
        return{
        isLike: false
        }
    },
    methods:{
      Reply(){
      //   this.Popupshow = true
      //   let { replyList } = this
     
      this.$emit('ReplyTwo')
      },
      commentLike(){
        let comment_id = sessionStorage.getItem('reply_comment_id')
        let { uid: user_id } = localStorage
      if(!this.isLike){
        commentlike(user_id,comment_id).then(res => {
          this.$toast(res.data.msg)
          this.isLike = true
        })
      }else{
         recommentlike(user_id,comment_id).then(res => {
          this.$toast(res.data.msg)
          this.isLike = false
        })
      }
      }
    },
    created(){
      let { is_like } = this
      this.isLike = is_like
    },
    computed:{
      ...mapState(['replyList']),
      formatime(){
        return formatTime(this.time)
      },
      likecount(){
        if(this.like_count == 0){
          return ''
        }
          return this.like_count
        
      },
      replynum(){
        if(this.reply_num == 0){
          return ''
        }
        return this.reply_num
      }
    }
}
</script>

<style lang="less" scoped>
.comment {
  height: calc(100vh -60px);
    &:last-child{
    margin-bottom: 100px;
    }
  .comment_userinfo {
    line-height: 30px;
    padding-top: 16px;
    display: flex;
    .userinfo_left {
      flex: 1;
      display: flex;
      img {
        width: 30px;
        height: 30px;
        border-radius: 15px 15px;
        margin-left: -15px;
        margin-right: 10px;
      }
    }
    .userinfo_right {
      text-align: right;
      flex: 1;
      .sum {
        margin-right: 35px;
      }
    }
  }

  .content {
    margin: 10px 0 10px 24px;
    width: 90%;
    word-wrap: break-word;
  }

  .footer {
    display: flex;
    justify-content: space-between;
    padding: 0 0 0 18px;
    .footer_left {
      display: flex;
      p {
        font-size: 12px;
        height: 25px;
        line-height: 25px;
        padding: 0 5px;
        margin-right: 15px;
        border-radius: 15px;
        background-color: rgb(240, 240, 240);
        font-family: "微软雅黑";
      }
      span {
        font-size: 12px;
        line-height: 25px;
        color: rgb(186, 186, 186);
      }
    }
  }
}
</style>